USE [Smart]
GO

/****** Object:  Table [dbo].[MealCategory]    Script Date: 06/01/2012 20:52:58 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[MealCategory](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Category] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_MealCategory] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

USE [Smart]
GO

/****** Object:  Table [dbo].[Meal]    Script Date: 06/01/2012 20:53:06 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Meal](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[CategoryId] [int] NOT NULL,
	[MealName] [nvarchar](50) NOT NULL,
	[Details] [nvarchar](100) NULL,
	[Energy] [float] NOT NULL,
	[Proteins] [float] NOT NULL,
	[Carbs] [float] NOT NULL,
	[Fats] [float] NOT NULL,
 CONSTRAINT [PK_Meal] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[Meal]  WITH CHECK ADD  CONSTRAINT [FK_Meal_MealCategory] FOREIGN KEY([CategoryId])
REFERENCES [dbo].[MealCategory] ([Id])
GO

ALTER TABLE [dbo].[Meal] CHECK CONSTRAINT [FK_Meal_MealCategory]
GO

USE [Smart]
GO

/****** Object:  Table [dbo].[MealLog]    Script Date: 06/01/2012 20:53:15 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[MealLog](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[CreatedBy] [int] NOT NULL,
	[CreatedOn] [datetime] NULL,
	[MealId] [int] NOT NULL,
	[Quantity] [int] NULL,
	[Energy] [float] NULL,
	[Proteins] [float] NULL,
	[Carbs] [float] NULL,
	[Fats] [float] NULL,
 CONSTRAINT [PK_MealLog] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[MealLog]  WITH CHECK ADD  CONSTRAINT [FK_MealLog_User] FOREIGN KEY([CreatedBy])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[MealLog] CHECK CONSTRAINT [FK_MealLog_User]
GO
ALTER TABLE [dbo].[MealLog]  WITH CHECK ADD  CONSTRAINT [FK_MealLog_Meal] FOREIGN KEY([MealId])
REFERENCES [dbo].[Meal] ([Id])
GO

ALTER TABLE [dbo].[MealLog] CHECK CONSTRAINT [FK_MealLog_Meal]
GO



